package com.demo.chapter12date;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

//用long表示从1970-1-1 00:00:00到现在的nanosecond
public class InstantDemo {

	public static void demo(){
		Instant instant = Instant.ofEpochSecond(3);
		Instant instant2 = Instant.ofEpochSecond(3, 0);
		//2秒之后再加上1_000_000_000纳秒
		Instant instant3 = Instant.ofEpochSecond(2, 1_000_000_000);
		//4秒之后再减去1_000_000_000纳秒
		Instant instant4 = Instant.ofEpochSecond(4, -1_000_000_000);

        Instant now = Instant.now();
        System.out.println(now);

        //时区的操作：获取北京时间
        OffsetDateTime now2 = now.atOffset(ZoneOffset.ofHours(8));
        System.out.println(now2);
	}

	public static void main(String[] args) {
		demo();
	}

}
